package com.example.login;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

    Button btn_login;//登录按钮
    CheckBox mCheckBox;
    EditText mName;
    EditText mPwd;
    TextView mReg;
    TextView mfindpwd;//找回密码
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mName = findViewById(R.id.et_name);
        mPwd = findViewById(R.id.et_pwd);
        btn_login = findViewById(R.id.btn_login);//绑定登录按钮
        mReg = findViewById(R.id.btn_reg);//绑定注册按钮
        mfindpwd = findViewById(R.id.btn_findpwd);


        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(MainActivity.this, "我点击了登录按钮", Toast.LENGTH_SHORT).show();
                String username = mName.getText().toString();//用户输入用户名和密码
                String password = mPwd.getText().toString();

                if(TextUtils.isEmpty(username)||TextUtils.isEmpty(password)){
                    Toast.makeText(LoginActivity.this, "请输入用户名或密码", Toast.LENGTH_SHORT).show();
                }

                if(username.equals("123")&&password.equals("123")){
                    Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent();
                    intent.setClass(LoginActivity.this, SuccessActivity.class);
                    startActivity(intent);
                }

                if((!TextUtils.isEmpty(username)&&!TextUtils.isEmpty(password))&&(!username.equals("123")||!password.equals("123"))){
                    Toast.makeText(LoginActivity.this, "用户名或密码错误，请重试！", Toast.LENGTH_SHORT).show();
                }

            }
        });

        mReg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(LoginActivity.this, "欢迎注册", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent();
                intent.setClass(LoginActivity.this, RegisterActivity.class);
                startActivity(intent);
            }
        });

        mfindpwd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(LoginActivity.this, "龙牙还在努力中~敬请期待", Toast.LENGTH_SHORT).show();
            }
        });


    }
}